<template>
   <div id="app">
      我是首页<br />
      {{num}}---{{num2}}
   </div>
</template>
<script setup>
import {ref, computed,watch,onMounted} from 'vue'
const num = ref(100)
const num2 = computed(()=>{
    return num.value *2 
})
//watch
watch(num,(n1,n2)=>{    //n1 num变化后,n2 num 变化前
    setTimeout(()=>{
        console.log("aaaa")
    },2000)
    console.log(1,n1,n2)  //1 200 100
},{immediate:true})
onMounted(()=>{
    setTimeout(()=>{
        num.value=200
    },2000)
})
</script>
<style>
</style>


 
 
